package com.tensquare.search.service;

import com.tensquare.search.dao.ArticleSearchRepository;
import com.tensquare.search.pojo.Article;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

/**
 * @author fangyu
 * @version v1.0.0
 * @date 2020/10/14 12:41 下午
 */
@Service
public class ArticleSearchService {

    @Autowired
    private ArticleSearchRepository articleSearchRepository;

    /**
     * 增加文章
     * @param article
     */
    public void add(Article article) {
        articleSearchRepository.save(article);
    }

    /**
     * 检索
     * @param keywords
     * @param page
     * @param size
     * @return
     */
    public Page<Article> findByTitleLike(String keywords, int page, int size) {
        PageRequest pageRequest = PageRequest.of(page-1, size);
        return articleSearchRepository.findByTitleOrContentLike(keywords, keywords, pageRequest);
    }
}
